package org.dromara.hotel.util;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class DateUtils {
    public static List<LocalDate> getDateRange(LocalDate startDate, LocalDate endDate){
        // 验证日期顺序
        if (startDate.isAfter(endDate)) {
            throw new IllegalArgumentException("开始日期不能晚于结束日期");
        }
        List<LocalDate> dates = new ArrayList<>();
        LocalDate currentDate = startDate;

        while (!currentDate.isAfter(endDate)) {
            dates.add(currentDate);
            currentDate = currentDate.plusDays(1);
        }

        return dates;
    }
    public static void main(String[] args) {
        LocalDate start = LocalDate.of(2023, 1, 1);
        LocalDate end = LocalDate.of(2023, 1, 5);

        List<LocalDate> dateRange = getDateRange(start, end);

        System.out.println("生成的日期范围（共" + dateRange.size() + "天）：");
        dateRange.forEach(System.out::println);
    }
}
